package naive2;

import java.util.List;

import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
import entities.Doc;

//convert document to BoW
public class Doc2BoW {
	private StanfordCoreNLP pipeline;
	public Doc2BoW(StanfordCoreNLP pipeline){
		this.pipeline = pipeline;
	}
	public BoW doc2bow(Doc doc){
		
		//remove all the xml tags in document
		String clean_txt = doc.getText().replaceAll("<.*?>", "");
		Annotation document = new Annotation(clean_txt);
		pipeline.annotate(document);
	    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	    
	    BoW bow = new BoW();
	    for(CoreMap sentence: sentences) {
	        // traversing the words in the current sentence
	        // a CoreLabel is a CoreMap with additional token-specific methods
	        for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
	          // this is the text of the token
	         // String word = token.get(TextAnnotation.class);
	          // this is the POS tag of the token
	          //String pos = token.get(PartOfSpeechAnnotation.class);
	      
	          String lemma = token.get(LemmaAnnotation.class);
	          if( lemma.equals("-LRB-")|| lemma.equals("-RRB-")|| lemma.equals("-lrb-")||lemma.equals("-rrb-")||lemma.equals(",")||lemma.equals(".")){
	        	  continue;
	          }
	          // also need to handle when lemma is punctation or "a" "the"
	          
	          
	          //System.out.println("word:"+word+",lemma:"+lemma+",pos:"+pos);
	          
	          //change to its low case, because in json File they are all low cased
	          lemma = lemma.toLowerCase();
	          bow.putWord(lemma);
	         
	        }

	      }
		
		
		return bow;
	}
	public static void main(String[]args){
		for(int i=0;i<5;i++){
			if(i==3){
				continue;
			}
			System.out.println(i);
		}
	}
}
